package com.tchintech.pay.view.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.tchintech.pay.R;
import com.tchintech.pay.delegate.fragment.WalletFragmentDelegate;
import com.tchintech.pay.frame.presenter.FragmentPresenter;
import com.tchintech.pay.utils.zxing.android.CaptureActivity;
import com.tchintech.pay.view.activity.OrderActivity;
import com.tchintech.pay.view.activity.QuickOrderActivity;
import com.tchintech.pay.view.activity.ScanOrderActivity;

import static android.app.Activity.RESULT_OK;

/**
 * Created by Administrator on 2017/7/5 0005.
 */

public class WalletFragment extends FragmentPresenter<WalletFragmentDelegate> implements View.OnClickListener {
    private static final int REQUEST_CODE_SCAN = 1575;
    private static final String DECODED_CONTENT_KEY = "codedContent";
    private static final String DECODED_BITMAP_KEY = "codedBitmap";
    private Intent intent = new Intent();

    @Override
    protected Class<WalletFragmentDelegate> getDelegateClass() {
        return WalletFragmentDelegate.class;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        super.initView();
        viewDelegate.setOnClickListener(this, R.id.wallet_ll_toCreateOrder, R.id.rl_wallet_swingcard, R.id.qrCode, R.id.image2);
    }

    @Override
    protected void initData() {
        super.initData();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.wallet_ll_toCreateOrder:
            case R.id.image2:
                intent = new Intent(getActivity(), OrderActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_wallet_swingcard:
                intent = new Intent(getActivity(), QuickOrderActivity.class);
                startActivity(intent);
                break;

            case R.id.qrCode:
                intent = new Intent(getActivity(), CaptureActivity.class);
                startActivityForResult(intent, REQUEST_CODE_SCAN);
                System.out.println("跳转");
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_SCAN && resultCode == RESULT_OK) {
            String c = data.getStringExtra(DECODED_CONTENT_KEY);
            //showMsg("解码结果：" + c);
            // Intent intent = new Intent(getActivity(), ScanOrderActivity.class);
            intent.setClass(getActivity(), ScanOrderActivity.class);
            intent.putExtra("AuthCode", c);
            startActivity(intent);
        }

    }
}
